import dictApi from '@/api/dict';
export default{
    data(){
        return{
            infoCount:0,
            infoQuery:{
                page:0,
                pageSize:20,
                zdbh:''
            },
            details:[]
        }
    },
    methods:{
        loadInfo(){

            if( !this.dictRow ){
                return;
            }
            this.loading = true;
            this.infoQuery.zdbh = this.dictRow.zdbh;
            
            dictApi.queryDictInfo(this.infoQuery)
            .then(response => {
                const { data } = response;
                if( data.error_code == 0 ){
                    
                    this.details = data.list;
                    this.infoCount = data.totalCount;
                }else{
                }
                this.loading = false;
            }).catch(error => {
                this.loading = false;
            });
        },
        onAddInfo(){
            this.$refs.infoForm.show({zdbh:this.dictRow.zdbh})
            .then((action)=>{
                if( action === 'ok'){
                    this.loadInfo();
                }
            });
        },
        onEditInfo(row){
            this.$refs.infoForm.show(row)
            .then((action)=>{
                if( action === 'ok'){
                    this.loadInfo();
                }
            });
        },
        onDeleteInfo(row){
            this.$confirm('是否删除该条目？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                closeOnClickModal:false
            }).then((action) => {
                this.deleteInfo(row);
            }).catch((action) => {
            });
        },
        deleteInfo(row){
            const ids = []
            ids.push(row.tmzj)
            
            dictApi.delDictInfo(ids)
            .then(response => {
                const { data } = response;
                if(data.error_code == 0){
                    this.loadInfo();
                    this.showInfo("操作成功！");
                }else{
                    this.showError("操作失败！");
                }
            }).catch(error => {
                this.showError("操作失败！");
            });
        },
        onInfoPageChange(obj){
            this.infoQuery.pageSize = obj.pageSize;
            this.infoQuery.page = obj.currentPage;
            this.loadInfo();
        }
    }
}